/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-11-07
 * Time: 12:19
 */
//创建树节点
class TreedNode {
    public char val;
    public TreedNode left;
    public TreedNode right;
    public TreedNode(char val){
        this.val = val;
    }
}


public class BinaryTree {

    //穷举创建树节点
    public TreedNode createTree(){
        TreedNode A = new TreedNode('A');
        TreedNode B = new TreedNode('B');
        TreedNode C = new TreedNode('C');
        TreedNode D = new TreedNode('D');
        TreedNode E = new TreedNode('E');
        TreedNode F = new TreedNode('F');
        TreedNode G = new TreedNode('G');
        TreedNode H = new TreedNode('H');

        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        E.right = H;
        //返回根节点
        return A;

    }

    //前序遍历 根左右
    void preOrder(TreedNode root){
        if (root == null){
            return;
        }
        System.out.print(root.val + " ");
        preOrder(root.left);
        preOrder(root.right);
    }

    //中序遍历
    void inOrder(TreedNode root){
        //左根右
        if (root == null){
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }

    //后序遍历 左右根
    void postOrder(TreedNode root){
        if (root == null){
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.val + " ");
    }
}
